home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / Basic Classes / Z Headers / ZDialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-21  |  6.3 KB  |  211 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZDialog.h            -- a dialog box
  9. *
  10. *            
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *            Additional modifications/enhancements by Joe Strout.
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21. #pragma once
  22.  
  23. #ifndef __ZDIALOG__
  24. #define    __ZDIALOG__
  25.  
  26. #ifndef __ZWINDOW__
  27. #include    "ZWindow.h"
  28. #endif
  29.  
  30. typedef struct
  31. {
  32.     short    item;
  33.     short    groupID;
  34. }
  35. RGroupEntry, *RGroupPtr, **RGroupHdl;
  36.  
  37. // 'ictb' parsing stuff:
  38.  
  39. #if PRAGMA_ALIGN_SUPPORTED
  40. #pragma options align=mac68k
  41. #endif
  42.  
  43. // first part of resource is array of these:
  44.  
  45. typedef struct
  46. {
  47.     unsigned short    iData;            // item data flags (enumerated below)
  48.     unsigned short    iOffset;        // offset to data table
  49. }
  50. ictbItemEntry, *ictbPtr, **ictbHandle;
  51.  
  52. // text info stored in tables like this:
  53.  
  54. typedef struct
  55. {
  56.     short            txtFont;        // font ID or offset to name
  57.     Style            txtFace;        // face- plain, bold, etc
  58.     char            filler;
  59.     short            txtSize;        // font size
  60.     RGBColor        txtFColour;        // text colour
  61.     RGBColor        txtBColour;        // background colour
  62.     short            txtMode;        // transfer mode
  63. }
  64. ictbTextStyleTable, *ictbTablePtr;
  65.  
  66. // iData is bitfield arranged thus:
  67.  
  68. enum
  69. {
  70.     fFamChange        = 1,            // change the font
  71.     fFaceChange        = 2,            // change the face
  72.     fSizeChange        = 4,            // change the size
  73.     fFColourChange    = 8,            // change the colour
  74.     fAddFontSize    = 16,            // add the size
  75.     fBColourChange    = 8192,            // change the background colour
  76.     fModeChange        = 16384,        // change the mode
  77.     fIsFNameOffset    = 32768            // txtFont is offset to font name
  78. };
  79.  
  80.  
  81. #if PRAGMA_ALIGN_SUPPORTED
  82. #pragma options align=reset
  83. #endif
  84.  
  85. // message sent to dialog's boss when dialog closed OK. You can listen for this
  86. // so that you get informed when the user closes the dialog. The boss listens for
  87. // this anyway- you just need to override ReceiveMessage to take action.
  88.  
  89. enum
  90. {
  91.     kMsgDialogSuccessfullyClosed = 'dlg$',
  92.     kMsgDialogCancelled             = 'dlg-'
  93. };
  94.  
  95. // class definition
  96.  
  97. class    ZDialog : public ZWindow
  98. {
  99. protected:
  100.     Boolean            isModal;        // TRUE if dialog is modal
  101.     RGroupHdl        rGroupList;        // array of rGroupEntrys for managing radio groups
  102.     ictbHandle        ictb;            // local handle to ictb resource, if any
  103.     short            signalDismiss;    // set to ok or cancel to close dialog safely in response to messages
  104.     
  105. public:
  106.     
  107.     ZDialog(ZCommander* aBoss, const short dialogID);
  108.     virtual ~ZDialog();
  109.     
  110.     virtual void    InitZWindow();
  111.     virtual void    Draw();
  112.     virtual Boolean    Close(const short phase);
  113.     virtual void    AdjustCursor(const Point mouse, const short modifiers);
  114.     virtual void    Click( const Point mouse, const short modifiers );
  115.     virtual void    Activate();
  116.     virtual void    Deactivate();
  117.     virtual void    Idle();
  118.     virtual void    Type( const char theKey );
  119.  
  120.     // command stuff
  121.     
  122.     virtual void    UpdateMenus();
  123.     
  124.     // std edit commands
  125.     
  126.     virtual Boolean    CanPasteType();
  127.     virtual void    DoCut();
  128.     virtual void    DoCopy();
  129.     virtual void    DoPaste();
  130.     virtual void    DoClear();
  131.     
  132.     // dialog specific stuff
  133.     
  134.     virtual void    SetUp();
  135.     virtual void    ClickItem( const short theItem );
  136.     virtual Boolean    CloseDialog();
  137.     virtual Boolean    Filter( EventRecord* theEvent );
  138.     virtual void    DrawUserItem( const short item );
  139.     
  140.     // convenience functions
  141.     
  142.     virtual void    SetValue( const short item, const long value );
  143.     virtual void    SetValue( const short item, const int value )     { SetValue(item, (long) value); }
  144.     virtual void    SetValue( const short item, const short value )    { SetValue(item, (long) value); }
  145.     virtual void    SetValue( const short item, const Str255 value );
  146.     virtual void    SetValue( const short item, const double value );
  147.     virtual void    SetValue( const short item, const float value )    { SetValue(item, (double) value); }
  148.     
  149.     virtual long    GetValue( const short item );
  150.     virtual void    GetValueAsText( const short item, Str255 aStr );
  151.     virtual float    GetValueAsFloat( const short item );
  152.     virtual void    HiliteItem( const short item, const short state );
  153.     virtual void    OutlineDefaultItem();
  154.     virtual void    GetItemBounds( const short item, Rect* bounds );
  155.     virtual short    FindItem( const Point localMouse );
  156.     
  157.     inline    Boolean    IsModal() { return isModal; };
  158.     
  159. protected:
  160.  
  161.     virtual void    MakeMacWindow( const short dialogID );
  162.     virtual Boolean    HasEditFields();
  163.     virtual void    SetUpUserItems();
  164.     virtual void    SetUpRadioGroups();
  165.     virtual void    ParseRButtonTitle( Str255 buttonTitle, short* groupID, Boolean* isDefault );
  166.     virtual void    HandleRButtonGroupClick( const short item );
  167.     virtual void    FakeClick( const short item );
  168.     virtual short    GetItemType( const short item );
  169.     
  170.     // ictb stuff:
  171.     
  172.     virtual void    SetTEItemDataFromIctb( const short teItem, Boolean applyChanges = TRUE );
  173.     virtual void    AddGreyscaleEffects();
  174. };
  175.  
  176. /*
  177.  
  178. This is a ZWindow that manages a modal or modeless dialog using the dialog manager. For specific
  179. dialogs, you need to override the SetUp, ClickItem and CloseDialog methods to handle your par-
  180. ticular items. The rest is done for you. Moveable modals just work- no special effort. 
  181.  
  182. This class now handles radio button groups in a very easy to set up way. In your dialog
  183. template (DITL), append a double-slash plus a number to the name of a button to set the group
  184. the button is a part of- e.g. "My Button//1". The appended info is used to set up a table of
  185. radio groups that is private to ZDialog. Naturally buttons with the same number interact as
  186. a group. The extra information in the button title is removed
  187. and is not visible when the dialog is shown. Clicks in such buttons are handled internally by
  188. the default ClickItem() method. If you want to handle radio groups yourself in the old way (i.e.
  189. without any help from ZDialog, simply leave off the group info in the button title. Thus this
  190. is entirely backward-compatible, too! Now was that so hard that Apple couldn't have put this
  191. into the Dialog Manager?
  192.  
  193. */
  194.  
  195. // method to convert real numbers to strings (without using ANSI library)
  196. void RealToString( const double num, Str255& str );
  197.  
  198. // compiler flags:
  199.  
  200. // this class can now provide some support for the Apple Grayscale Appearance. If you do not want this
  201. // additional support ( which draws 3D borders around edit fields and list boxes and draws user items as
  202. // a 3D embossed line ), comment out the following compiler flag
  203.  
  204. #define        _GREYSCALE_APPEARANCE    1
  205.  
  206. // static function for drawing 3D effect rectangles:
  207.  
  208. void    FrameGrayRect( Rect* aRect );
  209.  
  210.  
  211. #endif